<?php

class day {

private $vars = array();

function __construct( $ymd = '00000000' ) {

    if ( $ymd == '00000000' ) {
        $ymd = date('Ymd');
    }

    $this->vars['ymd'] = $ymd;
    $this->ymd_bits();
}

function year() {
    if ( $this->vars['year'] ) {
        // We already know - return from cache
    } else {
        $this->ymd_bits();
    }
    return $this->vars['year'];
}

function gmtime() {
    $t = mktime( 0,0,0, $this->month(), $this->day(), $this->year() );
    return $t;
}

function ymd_bits() {
    $x = str_split( $this->vars['ymd'] );
    $this->vars['year']  = $x[0].$x[1].$x[2].$x[3];
    $this->vars['month'] = $x[4].$x[5];
    $this->vars['day']   = $x[6].$x[7];
}

function __call($name, $args) {

    // year, month, day
    if ( $name == 'year' || $name == 'month' || $name == 'day' ) {
        if (! $this->vars[$name]) {
            $this->ymd_bits();
        }
        return $this->vars[$name];
    }

    if ( $this->vars[$name] ) {
        return $this->vars[$name];
    } else {
        // For everything else ...
        error_log( "Method $name called on a day. Not sure what that is.");
    }
}

/**
 * Tomorrow
 *
 * @param
 * @return tomorrow
 */
function yesterday() {
}

/**
 * Yesterday
 *
 * @param
 * @return yesterday
 */

function yesterday() {
}

} 

?>
